module.exports = {
	prefix: "/bus/extend/purchase",
	get: {
		"/by_id/:purchase_id": function() {
			var bus = role.getBus(this);
			var purchase_id = this.params.purchase_id;
			var query = this.request.query;

			this.body = ResponObj("json", bus.getPurchaseById(purchase_id))
		},
		"/list/with_page_info": function() {
			var bus = role.getBus(this);
			var query = this.request.query;
			this.body = ResponObj("json", bus.getPurchaseList_WithPageInfo(query.num, query.page, query));
		},
		"/search/material": function() {
			var bus = role.getBus(this);
			var query = this.request.query;
			this.body = ResponObj("json", bus.searchMaterialList(query));
		},
		"/material/list/with_page_info": function() {
			var bus = role.getBus(this);
			var query = this.request.query;
			this.body = ResponObj("json", bus.getMaterialList_WithPageInfo(query.num, query.page, query));
		},
		"/material/by_id/:material_id": function() {
			var bus = role.getBus(this);
			var material_id = this.params.material_id;

			this.body = ResponObj("json", bus.getMaterialById(material_id));
		},
		"/logs/list/transform_material_to_goods": function() {
			var bus = role.getBus(this);
			var query = this.request.query;
			this.body = ResponObj("json", bus.getTMGLogs(query.num, query.page, query));
		}
	},
	post: {
		"/add_purchase": function() {
			var bus = role.getBus(this);
			var body = this.request.body;
			var purchase = bus.addPurchase(body);

			this.body = ResponObj("json", purchase);
		}
	},
	put: {
		"/update_purchase/:purchase_id": function() {
			var bus = role.getBus(this);
			var purchase_id = this.params.purchase_id;
			var body = this.request.body;
			var purchase = bus.updatePurchase(purchase_id, body);

			this.body = ResponObj("json", purchase);
		},
		"/transform_material_to_goods": function() {
			var bus = role.getBus(this);
			var body = this.request.body;
			if (!(Array.isArray(body.goods_list_info) && Array.isArray(body.material_list_info))) {
				throwCusError("参数错误")
			}
			this.body = ResponObj("json", bus.transformMaterialsToGoods(body.goods_list_info, body.material_list_info));
		}
	},
	"delete": {
		"/remove_purchase/:purchase_id": function() {
			var bus = role.getBus(this);
			var purchase_id = this.params.purchase_id;
			var body = this.request.body;
			bus.removePurchase(purchase_id);
			this.body = ResponObj("string", "success:" + purchase_id);
		},
		"/test": function() {
			console.log(this.request.headers);
			console.log(this.request.body);
			this.body = ResponObj("json", this.request.body)
		}
	},
}
var role = require("./role");
var BusCon = require("../../core/bus/_con");
var UserCon = require("../../core/user/_con");
var GoodsCon = require("../../core/goods/_con");
var AchCon = require("../../core/ach/_con");
var db = require("../../core/db/index");
var config = require("../../core/_include/config");
var ResponObj = require("../_include/responObj");